﻿using System.Web.UI;
using Ue.Framework.Web;
using Ue.Qcdz.Domain;
using Ue.Qcdz.Domain.Articles;
using System;
namespace Ue.Qcdz.UI.Controls
{
    public class Breadcrumb : Control, INamingContainer
    {

        protected override void Render(HtmlTextWriter writer)
        {
            //
            if (!string.IsNullOrEmpty(NodeId))
            {
                Domain.TreeViews.TreeNode node = ArticleService.TagTreeView.FindNodeBy(NodeId);
                if (node != null)
                {
                    string lump = "<a href=\"" + SiteUrls.Instance.NewsList(node.Key) + "\">" + node.Tag.Name + "</a>  &gt; ";

                    for (int i = 0; i < 10; i++)
                    {
                        node = node.Parent;
                        if (node == null)
                            break;
                        lump = "<a href=\"" + SiteUrls.Instance.NewsList(node.Key) + "\">" + node.Tag.Name + "</a>  &gt; " + lump;

                    }
                    writer.Write(lump);
                }
            }
            //
            if (!string.IsNullOrEmpty(NewsId))
            {
                Article model = ArticleService.GetArticle(new Guid(NewsId));
                if (model == null)
                    return;
                //
                writer.AddAttribute(HtmlTextWriterAttribute.Href, "" + SiteUrls.Instance.NewsList(model.Tag.Key));
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(model.Tag.Name);
                writer.Write("   &gt; ");
                writer.RenderEndTag();
            }
            //
            if (!string.IsNullOrEmpty(KeyWord))
            {
                writer.Write("搜索结果：");
            }
        }




        public string NodeId
        {
            get
            {
                return Page.Request.GetQueryValue<string>("NodeId");
            }
        }

        public string NewsId
        {
            get
            {
                return Page.Request.GetQueryValue<string>("Id");
            }
        }


        public string KeyWord
        {
            get
            {
                return Page.Request.GetQueryValue<string>("Title");
            }
        }

    }
}
